using LitJson;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;

namespace SimpleFramework
{
    public static class Requests
    {
        public static void Get(
            string url, 
            UnityAction<IRequestHandler, string> complete,
            Dictionary<string, string> headers = null)
        {
            var request = RequestGetCommand.POOL.Spawn();
            request.Reset();
            request.Url = url;
            request.Complete.AddListener(complete);
            request.SetHeaders(headers);
            request.Start();
        }

        public static void Post(
            string url, 
            string postData, 
            UnityAction<IRequestHandler, string> complete,
            Dictionary<string, string> headers = null)
        {
            var request = RequestPostCommand.POOL.Spawn();
            request.Reset();
            request.Url = url;
            request.PostData = postData;
            request.Complete.AddListener(complete);
            request.SetHeaders(headers);
            request.Start();
        }

        public static void Post(
            string url,
            WWWForm formData,
            UnityAction<IRequestHandler, string> complete,
            Dictionary<string, string> headers = null)
        {
            var request = RequestPostCommand.POOL.Spawn();
            request.Reset();
            request.Url = url;
            request.FormData = formData;
            request.Complete.AddListener(complete);
            request.SetHeaders(headers);
            request.Start();
        }

        public static void Post(
            string url,
            Dictionary<string, string> formFields,
            UnityAction<IRequestHandler, string> complete,
            Dictionary<string, string> headers = null)
        {
            var request = RequestPostCommand.POOL.Spawn();
            request.Reset();
            request.Url = url;
            request.FormFields = formFields;
            request.Complete.AddListener(complete);
            request.SetHeaders(headers);
            request.Start();
        }
    }
}